package com.hst.capacity.facade.rest;

import cn.hutool.core.util.StrUtil;
import com.hst.capacity.application.biz.FranchiseeUserBiz;
import com.hst.capacity.domain.exception.BusinessException;
import com.hst.capacity.domain.model.request.RePasswordParam;
import com.hst.capacity.domain.model.request.franchisee.FranchiseeUserParam;
import com.hst.capacity.domain.model.request.franchisee.FranchiseeUserListParam;
import com.hst.capacity.domain.model.response.DefaultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import java.util.Map;

import static com.hst.capacity.domain.model.response.DefaultVO.success;

/**
 * 运力商用户账号Controller
 */
@RequestMapping("/franchisee/user")
@RestController
public class FranchiseeUserController {

    @Autowired
    private FranchiseeUserBiz franchiseeUserBiz;

    @PostMapping("/add")
    private DefaultVO add(@RequestBody @Valid FranchiseeUserParam param) {
        return success(franchiseeUserBiz.add(param));
    }

    @PostMapping("/edit")
    private DefaultVO edit(@RequestBody @Valid FranchiseeUserParam param) {
        return success(franchiseeUserBiz.edit(param));
    }

    @PostMapping("/list")
    private DefaultVO list(@RequestBody @Valid FranchiseeUserListParam param) {
        return success(franchiseeUserBiz.list(param));
    }

    @PostMapping("/select")
    private DefaultVO select(@RequestBody Map<String,String> param){
        String idFranchiseeUser = param.get("idFranchiseeUser");
        if (StrUtil.isEmpty(idFranchiseeUser))
            throw new BusinessException(4001,"用户ID[idFranchiseeUser]不能为空");
        return success(franchiseeUserBiz.select(idFranchiseeUser));
    }

    @PostMapping("/id")
    private DefaultVO sreachByUserID(@RequestBody Map<String,String> param){
        String idFranchiseeUser = param.get("userID") ;
        if (StrUtil.isEmpty(idFranchiseeUser))
            throw new BusinessException(4001,"用户ID[userID]不能为空");
        return success(franchiseeUserBiz.sreachByUserID(idFranchiseeUser));
    }

    /**
     * 修改密码
     *
     * */
    @PostMapping("/re/password")
    public DefaultVO rePassword(@RequestBody @Valid RePasswordParam param) {
        return success(franchiseeUserBiz.rePassword(param));
    }

}
